#!/bin/bash

# Test vdi snapshot functionality concurrently with object cache enabled

. ./common

for i in `seq 0 5`; do
    _start_sheep $i "-w size=1000M"
done

_wait_for_sheep 6

_cluster_format -c 6
_vdi_create base1 20M -p 7000
_vdi_create base2 20M -p 7001
_vdi_create base3 20M -p 7002

for i in `seq 0 4`; do
    echo $i | $DOG vdi write base1 $((i * 4 * 1024 * 1024)) 512
done &

for i in `seq 0 4`; do
    echo $i | $DOG vdi write base2 $((i * 4 * 1024 * 1024)) 512
done &

for i in `seq 0 4`; do
    echo $i | $DOG vdi write base3 $((i * 4 * 1024 * 1024)) 512
done &

wait

$DOG vdi snapshot -s snap0 base1 -p 7000
$DOG vdi snapshot -s snap0 base2 -p 7001
$DOG vdi snapshot -s snap0 base3 -p 7002
sleep 1

for i in `seq 1 10`; do
	$DOG vdi snapshot -s snap$i base1 -p 7000
	$DOG vdi delete -s snap$(($i - 1)) base1 -p 7000
	sleep 1
done &

for i in `seq 1 10`; do
	$DOG vdi snapshot -s snap$i base2 -p 7001
	$DOG vdi delete -s snap$(($i - 1)) base2 -p 7001
	sleep 1
done &

for i in `seq 1 10`; do
	$DOG vdi snapshot -s snap$i base3 -p 7002
	$DOG vdi delete -s snap$(($i - 1)) base3 -p 7002
	sleep 1
done &

wait

$DOG vdi delete base1 -p 7000
$DOG vdi delete base2 -p 7001
$DOG vdi delete base3 -p 7002
$DOG vdi delete -s snap10 base1 -p 7000
$DOG vdi delete -s snap10 base2 -p 7001
$DOG vdi delete -s snap10 base3 -p 7002

echo there should be no vdi
_vdi_list

echo there should be no object
_node_info

find $STORE/*/cache -type f | sort
